package com.zues.web.shopadmin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zues.dto.Result;
import com.zues.entity.ProductCategory;
import com.zues.entity.Shop;
import com.zues.enums.ProductCategoryEnum;
import com.zues.service.ProductCategoryService;

@Controller
@RequestMapping("/shopadmin")
public class ProductCategoryManagementController {
	
	@Autowired
	ProductCategoryService productCategoryService;
	
	@RequestMapping(value="/getproductcategorylist", method=RequestMethod.GET)
	@ResponseBody
	public Result<List<ProductCategory>> getProductCategoryList (HttpServletRequest request) {
		
		//to the removed
		//???
		Shop shop = new Shop();
		shop.setShopId(37L);
		request.getSession().setAttribute("currentShop", shop);
		
		Shop currentShop = (Shop) request.getSession().getAttribute("currentShop");
		List<ProductCategory> list = null;
		if(currentShop != null){
			list = productCategoryService.getProductCategoryList(currentShop.getShopId());
			return new Result<List<ProductCategory>>(true, list);
		}else{
			ProductCategoryEnum ps = ProductCategoryEnum.INNER_ERROR;
			return new Result<>(false, ps.getStateInfo(), ps.getState());
		}
		
	}
}
